package com.guet.user.controller;

import com.guet.common.response.ResultCodeEnum;
import com.guet.common.response.ResultVO;
import com.guet.user.beans.entity.User;
import com.guet.user.beans.vo.UserVO;
import com.guet.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * @author Li
 * @create 2022-12-16-21:47
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    IUserService userService;

    @RequestMapping("/login")
    public ResultVO<User> login(@RequestParam String userName, @RequestParam String pw){


        User user = userService.login(userName, pw);

        return new ResultVO<>(ResultCodeEnum.SUCCESS, user);
    }

    @PostMapping("/add")
    public ResultVO add(@Valid UserVO userVO,@RequestParam MultipartFile file){

        userService.add(userVO, file);


        return new ResultVO<>(ResultCodeEnum.SUCCESS);
    }

}
